<?php
if(isset($_POST['action'])){
	$db = new Database;
	$id = $_POST['id'];
	if($_POST['action']=="getTag"){
		$getData = $db->query("SELECT * FROM tag WHERE id = '$id'","array");
		foreach($getData as $row){
			?>
			<script>
				port = $("#portnumber").val("<?php echo $row['portNumber'] ?>");
				rack = $("#rack").val("<?php echo $row['rack'] ?>");
				cabinet = $("#cabinet").val("<?php echo $row['cabinet'] ?>");
				workstationType = $("#workstationType").val("<?php echo $row['workstation'] ?>");
				description = $("#description").val("<?php echo $row['description'] ?>");
				IPAddress = $("#IPAddress").val("<?php echo $row['ipAddress'] ?>");
				mac = $("#mac").val("<?php echo $row['mac'] ?>");
				directoryName = $("#directoryName").val("<?php echo $row['directoryName'] ?>");
				StationType = $("#StationType").val("<?php echo $row['stationType'] ?>");
				EAPBX = $("#EAPBX").val("<?php echo $row['eaPBX'] ?>");
				COS = $("#COS").val("<?php echo $row['classService'] ?>");
				vLan = $("#vLan").val("<?php echo $row['vLan'] ?>");
				localNumber = $("#localNumber").val("<?php echo $row['localNumber'] ?>");
				classService = $("#<?php echo $row['classService'] ?>").attr("selected","selected");
				StationType = $("#<?php echo $row['stationType'] ?>").attr("selected","selected");
				statusBlick = $("#<?php echo $row['statusBlink'] ?>").attr("selected","selected");
			</script>
			<?php
		}
	}elseif($_POST['action']=="editTag"){
		$port = $_POST['portnumber'];
		$cabinet = $_POST['cabinet'];
		$workstationType = $_POST['workstationType'];
		$description = $_POST['description'];
		$IPAddress = $_POST['IPAddress'];
		$mac = $_POST['mac'];
		$directoryName = $_POST['directoryName'];
		$StationType = $_POST['StationType'];
		$EAPBX = $_POST['EAPBX'];
		$COS = $_POST['COS'];
		$vLan = $_POST['vLan'];
		$localNumber = $_POST['localNumber'];
		$statusBlink = $_POST['statusBlink'];
		if($port=="" || $cabinet=="" || $workstationType=="" || $description=="" || $IPAddress=="" ||$mac=="" || $directoryName=="" || $EAPBX=="" || $vLan=="" || $localNumber==""){
			echo 0;
		}else{
			$db->query("UPDATE tag SET
				   portNumber ='$port',
				   cabinet = '$cabinet',
				   workstation = '$workstationType',
				   description = '$description',
				   ipAddress = '$IPAddress',
				   mac = '$mac',
				   directoryName = '$directoryName',
				   stationType = '$StationType',
				   eaPBX = '$EAPBX',
				   classService = '$COS',
				   vLan	 = '$vLan',
				   localNumber = '$localNumber',
				   statusBlink = '$statusBlink'
				   WHERE id = '$id'","update");
			echo 1;
		}
	}
}

?>